# 战斗日志UI组件
class_name BattleLog

var log_container: RichTextLabel
var max_log_entries: int = 10  # 最大显示的日志条数
var log_entries: Array = []


# 初始化战斗日志
func _init(container: RichTextLabel, max_entries: int = 10):
	log_container = container
	max_log_entries = max_entries
	clear_log()


# 添加日志条目
func add_entry(message: String, color: Color = Color(1, 1, 1, 1)):
	# 添加到日志数组
	log_entries.append({"message": message, "color": color})

	# 限制日志数量
	while log_entries.size() > max_log_entries:
		log_entries.pop_front()

	# 更新显示
	update_display()


# 清除日志
func clear_log():
	log_entries.clear()
	log_container.clear()


# 更新日志显示
func update_display():
	log_container.clear()

	for entry in log_entries:
		log_container.push_color(entry["color"])
		log_container.append_text(entry["message"] + "\n")
		log_container.pop()

	# 滚动到底部
	log_container.scroll_to_line(log_container.get_line_count())


# 添加战斗开始日志
func add_battle_start_log():
	add_entry("战斗开始！", Color(0.5, 0.8, 1, 1))


# 添加攻击日志
func add_attack_log(attacker_name: String, target_name: String, damage: int):
	add_entry("%s对%s造成了%d点伤害！" % [attacker_name, target_name, damage], Color(1, 0.5, 0.5, 1))


# 添加治疗日志
func add_heal_log(target_name: String, amount: int):
	add_entry("%s恢复了%d点生命值！" % [target_name, amount], Color(0.5, 1, 0.5, 1))


# 添加防御日志
func add_defend_log(character_name: String):
	add_entry("%s进入了防御状态！" % character_name, Color(0.8, 0.8, 0.8, 1))


# 添加回合开始日志
func add_turn_start_log(character_name: String):
	add_entry("%s的回合！" % character_name, Color(0.8, 0.5, 1, 1))


# 添加胜利日志
func add_victory_log():
	add_entry("战斗胜利！", Color(1, 1, 0, 1))


# 添加失败日志
func add_defeat_log():
	add_entry("战斗失败！", Color(1, 0.2, 0.2, 1))
